package light.mvc.controller.hrs;

import javax.servlet.http.HttpServletRequest;

import org.json.JSONArray;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import light.mvc.controller.base.BaseController;
import light.mvc.pageModel.base.Grid;
import light.mvc.pageModel.base.Json;
import light.mvc.pageModel.base.PageFilter;
import light.mvc.pageModel.hrs.HRSJudgement;
import light.mvc.pageModel.hrs.HRSJudgementEx;
import light.mvc.service.hrs.HRSJudgementServiceI;

@Controller
@RequestMapping("/hrsjudgement")
public class HRSJudgementController extends BaseController {
	@Autowired
	private HRSJudgementServiceI judgementService;
	
	@RequestMapping("/manager")
	public String manager(){
		return "/admin/habitus_research_sys/judgementEx";
	}
	
	 
	
	@RequestMapping("/dataGridEx")
	@ResponseBody
	public Grid dataGridEx(HRSJudgementEx judgementEx,PageFilter ph){
		Grid grid=new Grid();
		grid.setRows(judgementService.dataGridEx(judgementEx, ph));
		grid.setTotal(judgementService.count(ph));
		return grid;
	}
	
	@RequestMapping("/delete")
	@ResponseBody
	public Json delete(String ids, HttpServletRequest request){
		JSONArray jsonIds;
		Json j=new Json();
		try{
			jsonIds=new JSONArray(ids);
			for(int i=0;i<jsonIds.length();++i){
				long id=jsonIds.getLong(i);
				HRSJudgement r=judgementService.get(id);
				judgementService.delete(id, request);
			}
			j.setMsg("删除成功!");
			j.setSuccess(true);
		}catch(JSONException e){
			e.printStackTrace();
			j.setMsg(e.getMessage());
		}catch(Exception e1){
			j.setMsg(e1.getMessage());
		}
		return j;
	}
	@RequestMapping("/detailPage")
	public String detailPage(HttpServletRequest request,Long id){
		HRSJudgementEx r=judgementService.getEx(id);
		request.setAttribute("judgement", r);
		return "/admin/habitus_research_sys/judgementExDetail";
	}
}
